<?php

namespace console\migrations;

use console\migrations\Base;

/**
 * Handles the creation of table `{{%svn}}`.
 */
class M200810020125CreateSvnTable extends Base
{

    protected string $tableName = '{{%svn}}';
    protected string $tableComment = 'svn 编号';

    /**
     * {@inheritdoc}
     */
    public function safeUp()
    {
        $this->createTable( $this->tableName, [
            'id'   => $this->primaryKey(),
            'patch_id' => $this->integer( 11 )->notNull(),
            'code' => $this->integer( 11 )->notNull()->defaultValue( 0 ),
            'comment' => $this->string( 255 )->notNull()->defaultValue( '' ),
            'detail' => $this->text(),
            'environment' => $this->tinyInteger( 1 )->notNull()->defaultValue( 1 )->comment('环境 1 dev 2 dev2 3 rc 4 live'),
            'created_at' => $this->dateTime(),
            'updated_at' => $this->dateTime(),
        ], $this->tableOptions );

        $this->addForeignKey( 'fk-svn-patch', $this->tableName, 'patch_id', '{{%patch}}', 'id' );
    }

    /**
     * {@inheritdoc}
     */
    public function safeDown()
    {
        $this->dropForeignKey( 'fk-svn-patch', $this->tableName );

        $this->dropTable( '{{%svn}}' );
    }
}
